<template>
  <h1>EL - 员工列表综合作业练习</h1>

  <el-form style="width:600px;margin: 0 auto;">
    <el-form-item label="姓名">
      <el-input  placeholder="请输入姓名" v-model="emp.name" ></el-input>
    </el-form-item>

    <el-form-item label="工资">
      <el-input  placeholder="请输入工资" v-model="emp.salary" ></el-input>
    </el-form-item>

    <el-form-item label="工作">
      <el-input  placeholder="请输入工作" v-model="emp.job" ></el-input>
    </el-form-item>

    <el-form-item>
      <el-button type="success" @click="addEmp()">添加员工</el-button>
    </el-form-item>

  </el-form>

  <el-table :data="arr" style="width:600px;margin: 0 auto;">
<!--    <el-table-column label="编号" type="index"></el-table-column>"-->
<!--    <el-table-column label="姓名" prop="name"></el-table-column>-->
<!--    <el-table-column label="工资" prop="name"></el-table-column>-->
<!--    <el-table-column label="岗位" prop="name"></el-table-column>-->
    <el-table-column v-for="col in tableColumns"  v-bind="col"></el-table-column>
    <el-table-column label="操作" >
      <template #default="scope">
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>

  </el-table>


</template>

<script setup>

import {ref} from "vue";

const emp = ref( {name:'',salary:'',job:''})
const arr = ref([])

const addEmp = () =>{
  console.log({...emp.value});
  arr.value.push({...emp.value});
}

const del = (index,row) =>{
  if (confirm('确定删除吗？')){
    console.log("删除元素为: " + row )
    arr.value.splice(index,1);
  }
}

const tableColumns = ref([
  {type:'index',label:'编号',width:80},
  {label: '姓名',prop: 'name'},
  {label: '工资',prop: 'salary'},
  {label: '岗位',prop: 'job'},
])

</script>

<style scoped>

</style>